package com.anttribe.components.db.executor.entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
 * 执行结果
 * 
 * @author zhaoyong
 * @date 2023/1/3 0003
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class SqlExecuteResult<T> {

    /**
     * 默认成功响应码
     */
    public static final String DEFAULT_SUCCESS_RESULT_CODE = "000000";

    protected String code;

    protected String msg;

    protected T data;

    /**
     * 成功的结果
     * 
     * @return SqlExecuteResult<T>
     * @param <T>
     */
    public static <T> SqlExecuteResult<T> success() {
        return new SqlExecuteResult<T>(DEFAULT_SUCCESS_RESULT_CODE, "", null);
    }

    /**
     * 成功的结果
     *
     * @param data
     *            T
     * @param <T>
     * @return SqlExecuteResult<T>
     */
    public static <T> SqlExecuteResult<T> success(T data) {
        return new SqlExecuteResult<T>(DEFAULT_SUCCESS_RESULT_CODE, "", data);
    }

    /**
     * 失败的结果
     *
     * @param code
     *            响应码
     * @param msg
     *            消息
     * @param <T>
     * @return SqlExecuteResult<T>
     */
    public static <T> SqlExecuteResult<T> fail(String code, String msg) {
        return new SqlExecuteResult<T>(code, msg, null);
    }

}
